﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using DTO;
namespace DAL
{
   public class MenuDAL
    {

       DataTable dt;
       SqlDataAdapter apd;
       public DataTable MainMenu()
       {
           try
           {
               SqlConnection con = new SqlConnection();
               con = Connect.Connected();
               string sql = "SELECT * FROM Menu";
               SqlCommand cmd = new SqlCommand(sql, con);
               apd = new SqlDataAdapter(cmd);
               dt = new DataTable();
               apd.Fill(dt);
            
           }
           catch { }
           return dt; 
           #region proc

         
          
           //dt = new DataTable();
           //try
           //{
           //    SqlConnection conn = new SqlConnection();
           //    conn = Connect.Connected();
           //    SqlCommand cmd = new SqlCommand();
           //    cmd.Connection = conn;            
           //    cmd.CommandText = "sp_GetMenu_byLevel";
           //    cmd.CommandType = CommandType.StoredProcedure;
           //    cmd.Parameters.Add("@status", SqlDbType.Int).Value = stt;
           //    cmd.Parameters.Add("@level", SqlDbType.Int).Value = level;
           //    da = new SqlDataAdapter(cmd);
           //    da.Fill(dt);
            
           //}
           //catch
           //{

           //}

           //return dt;
           #endregion
       }
       #region all menu
       public List<Menu> MainMenu1()
       {
           List<Menu> listmenu = new List<Menu>();
           SqlConnection con = new SqlConnection();
           con = Connect.Connected();
           string sql = "SELECT * FROM Menu";
           SqlCommand cmd = new SqlCommand(sql, con);
           apd = new SqlDataAdapter(cmd);
           dt = new DataTable();
           apd.Fill(dt);

           int j=0;
           Menu a = new Menu();
           for (int i = 0; i < dt.Rows.Count;i++ )
           {
               a.Id = int.Parse(dt.Rows[i]["Id"].ToString());
               a.Level=int.Parse(dt.Rows[i]["Level"].ToString());
               a.Name = (dt.Rows[i]["Name"].ToString());
               a.Order = int.Parse(dt.Rows[i]["Order"].ToString());
               a.ParenId = int.Parse(dt.Rows[i]["ParenId"].ToString());
               a.Status = int.Parse(dt.Rows[i]["Status"].ToString());
               listmenu.Add(a);
           }
         
           return listmenu;
       }

       #endregion

    }
}
